package com.ruoyi.project.system.controller;

import java.util.List;

import com.ruoyi.project.system.domain.SysRole;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.domain.CityType;
import com.ruoyi.project.system.service.ICityTypeService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 城市分类关联Controller
 *
 * @author jjp
 * @date 2020-04-09
 */
@RestController
@RequestMapping("/city/type")
public class CityTypeController extends BaseController {
    @Autowired
    private ICityTypeService cityTypeService;

    /**
     * 查询城市分类关联列表
     */
    @PreAuthorize("@ss.hasPermi('city:type:list')")
    @GetMapping("/list")
    public TableDataInfo list(CityType cityType) {
        startPage();
        List<CityType> list = cityTypeService.selectCityTypeList(cityType);
        return getDataTable(list);
    }

    /**
     * 获取城市分类关联详细信息
     */
    @PreAuthorize("@ss.hasPermi('city:type:query')")
    @GetMapping(value = "/CityTypeMsg/{typeId}")
    public AjaxResult getInfo(@PathVariable("typeId") Long typeId) {
        return AjaxResult.success(cityTypeService.selectCityTypeById(typeId));
    }

    /**
     * 新增城市分类关联
     */
    @PreAuthorize("@ss.hasPermi('city:type:add')")
    @Log(title = "城市分类关联", businessType = BusinessType.INSERT)
    @PostMapping("/addCityType")
    public AjaxResult add(@RequestBody CityType cityType) {
        return toAjax(cityTypeService.insertCityType(cityType));
    }

    /**
     * 修改城市分类关联
     */
    @PreAuthorize("@ss.hasPermi('city:type:edit')")
    @Log(title = "城市分类关联", businessType = BusinessType.UPDATE)
    @PutMapping("/updateCityType")
    public AjaxResult edit(@RequestBody CityType cityType) {
        return toAjax(cityTypeService.updateCityType(cityType));
    }

    /**
     * 删除城市分类关联
     */
    @PreAuthorize("@ss.hasPermi('city:type:remove')")
    @Log(title = "城市分类关联", businessType = BusinessType.DELETE)
    @DeleteMapping("/deleteCityType/{typeIds}")
    public AjaxResult remove(@PathVariable Long[] typeIds) {
        return toAjax(cityTypeService.deleteCityTypeByIds(typeIds));
    }

    /**
     * 通过城市名称修改服务
     */
    @PostMapping("/updateCityService")
    @Log(title = "城市服务关联", businessType = BusinessType.INSERT)
    public AjaxResult dataScope(@RequestBody CityType cityType)
    {
        return toAjax(cityTypeService.updateCityService(cityType));
    }
}